package com.fankui.servicebase.exceptionhandler;

import com.fankui.commonutils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * ClassName GlobalExceptionHandler
 * Description TODO
 * Date 2023/11/16 15:20
 *
 * @Author 范奎
 * @Since JDK 11
 */
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    /**
     * 统一异常处理
     * @param e
     * @return
     */
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public R error(Exception e) {
        log.error(e.getMessage());
        e.printStackTrace();
        return R.error();
    }

    /**
     * 自定义异常处理
     * @param e
     * @return
     */
    @ExceptionHandler(LegendaryException.class)
    @ResponseBody
    public R error(LegendaryException e) {
        log.error(e.getMessage());
        e.printStackTrace();
        return R.error();
    }
}
